﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Assistant;
using YoucaiReader.Entities;

/**
 * 创建时间：2014/10/12 10:09:46
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace YoucaiReader.ViewModels
{
    internal class MarkerInfoListViewModel
    {
        public ObservableCollection<BookMarkerListModel> _T_MarkerInfoList;

        public void Add_MarkerInfoList(object indexItem)
        {
            this.T_MarkerInfoListViewModel().Insert(0, indexItem as BookMarkerListModel);
            SettingHelper.SaveInToSettings(App.ReaderFileName + "markerList", new List<BookMarkerListModel>(this.T_MarkerInfoListViewModel()));
        }

        public void Delete_MarkerInfoList(object indexItem)
        {
            this.T_MarkerInfoListViewModel().Remove(indexItem as BookMarkerListModel);
            if (this.T_MarkerInfoListViewModel().Count == 0)
            {
                SettingHelper.DeleteSettings(App.ReaderFileName + "markerList");
            }
            else
            {
                SettingHelper.SaveInToSettings(App.ReaderFileName + "markerList", new List<BookMarkerListModel>(this.T_MarkerInfoListViewModel()));
            }
        }

        public ObservableCollection<BookMarkerListModel> T_MarkerInfoListViewModel()
        {
            if ((this._T_MarkerInfoList == null) && SettingHelper.IsSettings(App.ReaderFileName + "markerList"))
            {
                this._T_MarkerInfoList = new ObservableCollection<BookMarkerListModel>((List<BookMarkerListModel>)SettingHelper.GetValueFromSettings(App.ReaderFileName + "markerList"));
            }
            return this._T_MarkerInfoList;
        }
    }
}
